<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="tiles" uri="http://struts.apache.org/tags-tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="c_rt" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fmt_rt" uri="http://java.sun.com/jstl/fmt_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>
<%@ taglib prefix="x_rt" uri="http://java.sun.com/jstl/xml_rt"%>
<%@ taglib prefix="wr_fn" uri="http://njo.org/taglib/functions"%>
<table width="98%">
  <tr>
    <td class="left"><a name="title"><b>编辑字段</b></a></td>
  </tr>
</table>
<c:set var="actionMessages" value="${wr_fn:amessages(pageContext, '')}"/>
<c:forEach items="${actionMessages}" var="item">
    <div class="error-content">${wr_fn:message(pageContext, item.key, item.values)}</div>
</c:forEach>
<form name="f2" action="${pageContext.request.contextPath}/processor.savefield.tiles" method="post">

<table class="forum" width="98%">
<col width="100"/>
<col width="*"/>
<tbody>
  <tr>
    <th colspan="2" align="left">字段信息</th>
  </tr>
  <tr>
    <td>物理名称:</td>
    <td>${field.field_physical_name}<input type="hidden" name="field_physical_name" value="${field.field_physical_name}"/></td>
  </tr>
  <tr>
    <td>逻辑名称:</td>
    <td><input type="text" name="field_logic_name" value="${field.field_logic_name}"/></td>
  </tr>
  <tr>
    <td>类型:</td>
    <td>
    <select id="field_type" name="field_type" onchange="javascript:type_change(this.value);">
    <option value=""></option>
<c:forEach items="${fieldTypeList}" var="item">
    <option value="${item.field_type}" ${field.field_type==item.field_type ? "selected" : ""}>${item.field_type}</option>
</c:forEach>
    </select>&nbsp;<input size="4" type="text" name="field_size" value="${field.field_size}"/>&nbsp;<script type="text/javascript">type_change($("field_type").value);</script>
    </td>
  </tr>
  <tr>
    <td>描述:</td>
    <td><textarea name="field_description">${field.field_description}</textarea></td>
  </tr>
</tbody>
</table>

<script type="text/javascript">
  <!--

  var ruleCount = ${wr_fn:length(wr_fn:isEmpty(field) ? paramValues.field_rule_name : field.field_rule_name)};
  function addRule() {
    var trElement;
    var tdElement;
    var classs;
    var tr_id;


    tr_id = "rule_" + ruleCount;
    
    classs = (ruleCount%2==0) ? 'even' : 'odd';
    
    trElement = document.createElement("tr");
    trElement.setAttribute("id", tr_id);
    trElement.setAttribute("class", classs);

    tdElement = document.createElement("td");
    tdElement.innerHTML = "<a title=\"编辑\" href=\"javascript:addSeatinfos();\"><img src=\"${pageContext.request.contextPath}/images/edit.png\" border=\"0\"/></a><a title=\"删除\" href=\"javascript:delRule(\'" + tr_id + "\');\"><img src=\"${pageContext.request.contextPath}/images/remove.png\" border=\"0\"/></a>" +
                          "<input type=\"hidden\" name=\"field_rule_name\" value=\"re\">";
    trElement.appendChild(tdElement);

    tdElement = document.createElement("td");
    tdElement.innerHTML = "必须输入";
    trElement.appendChild(tdElement);

    tdElement = document.createElement("td");
    tdElement.innerHTML = "<a href=\"${pageContext.request.contextPath}/processor.loadfield.tiles?name=${item.name}\">xxx.ddd.error.requ</a>";
    trElement.appendChild(tdElement);

    tdElement = document.createElement("td");
    tdElement.innerHTML = "none";
    trElement.appendChild(tdElement);

    tdElement = document.createElement("td");
    tdElement.innerHTML = "该字段必须输入";
    trElement.appendChild(tdElement);


    var validateRulesElement = $('validate_rules');
    if (ruleCount==0) {
        var xElement = $("rule_x");
        validateRulesElement.removeChild(xElement);
    }
    ruleCount++;
    validateRulesElement.appendChild(trElement);
  }

  function delRule(trId) {
    var i;
    var validateRulesElement = $('validate_rules');
    var oldElement = $(trId);
    if (!oldElement) {
        return;
    }
    validateRulesElement.removeChild(oldElement);
    
    var old_id_no = parseInt(trId.substring(trId.indexOf('_')+1));
    for (i=old_id_no+1;i<ruleCount;i++) {
      var nextElement = $("rule_" + i);
      if (!nextElement) {
        break;
      }
      var old_tr_id = "rule_" + (i);
      var new_tr_id = "rule_" + (i-1);
      nextElement.setAttribute("id", new_tr_id);
      var classs = ((i-1)%2==0) ? 'even' : 'odd';
      nextElement.setAttribute("class", classs);
      var tdE = nextElement.firstChild;
      var htmlStr = tdE.innerHTML;
      htmlStr = htmlStr.replace("javascript:delRule(\'" + old_tr_id + "\')", "javascript:delRule(\'" + new_tr_id + "\')");
      tdE.innerHTML = htmlStr;
    }

    ruleCount--;

    if (ruleCount==0) {
        var trElementx = document.createElement("tr");
        trElementx.setAttribute("id", "rule_x");
        trElementx.setAttribute("class", "even");
        var tdElementx = document.createElement("td");
        tdElementx.setAttribute("class", "center");
        tdElementx.setAttribute("colspan", "5");
        tdElementx.innerHTML = "没有设定输入验证规则";
        trElementx.appendChild(tdElementx);
        validateRulesElement.appendChild(trElementx);
    }

  }
  -->
</script>


<table class="forum" width="98%">
<col width="40"/>
<col width="80"/>
<col width="80"/>
<col width="80"/>
<col width="*"/>
<tbody id="validate_rules">
  <tr>
    <th><a title="追加" href="javascript:addRule();"><img src="${pageContext.request.contextPath}/images/add.png" border="0"/></a>&nbsp;<img src="${pageContext.request.contextPath}/images/space.png" border="0"/></th>
    <th>验证规则</th>
    <th>错误消息</th>
    <th>参数</th>
    <th>描述</th>
  </tr>
  <c:if test="${wr_fn:isEmpty(wr_fn:isEmpty(field) ? paramValues.field_rule_name : field.field_rule_name)}">
  <tr id="rule_x" class="even">
    <td class="center" colspan="5">没有设定输入验证规则</td>
  </tr>
  </c:if>
  <c:forEach var="item" varStatus="status" items="${wr_fn:isEmpty(field) ? paramValues.field_rule_name : field.field_rule_name}">
  <tr id="rule_${status.index}" class="${(status.index%2==0) ? 'even' : 'odd'}"><td><a title="编辑" href="javascript:addSeatinfos();"><img src="${pageContext.request.contextPath}/images/edit.png" border="0"/></a><a title="删除" href='javascript:delRule("rule_${status.index}");'><img src="${pageContext.request.contextPath}/images/remove.png" border="0"/></a><input type="hidden" name="field_rule_name" value="${item}"></td>
    <td>${item}</td>
    <td><a href="${pageContext.request.contextPath}/processor.loadfield.tiles?name=${item}">xxx.ddd.error.requ</a></td>
    <td>none</td>
    <td>none</td>
  </tr>
  </c:forEach>
  
  
</tbody>
</table>


<table width="98%">
  <tr>
    <td class="right"><input type="submit" name="save" value="保存"/> <input type="reset" name="reset" value="充填"/></td>
  </tr>
</table>
</form>